//
// Created by fanghr on 18-3-26.
//

#include "../include/acclen_data.h"

namespace acclsen_recv {
    time::time(const std::array<uint8_t, 11> &source) {
        y = source[2];
        m = source[3];
        d = source[4];
        h = source[5];
        m = source[6];
        s = source[7];
        ms = ((source[8] << 8) | source[9]);
    }

    acc::acc(std::array<uint8_t, 11> &source) {
        ax = ((source[3] << 8) | source[2]) / 32768 * 16 * 9.8;
        ay = ((source[5] << 8) | source[4]) / 32768 * 16 * 9.8;
        az = ((source[7] << 8) | source[6]) / 32768 * 16 * 9.8;
        t = ((source[9]) << 8 | source[8]) / 100;
    }

    angsp::angsp(std::array<uint8_t, 11> &source) {
        wx = ((source[3] << 8) | source[2]) / 32768 * 2000;
        wy = ((source[5] << 8) | source[4]) / 32768 * 2000;
        wz = ((source[7] << 8) | source[6]) / 32768 * 2000;
        t = ((source[9]) << 8 | source[8]) / 100;
    }

    ang::ang(std::array<uint8_t, 11> &source) {
        roll = ((source[3] << 8) | source[2]) / 32768 * 180;
        pitch = ((source[5] << 8) | source[4]) / 32768 * 180;
        yaw = ((source[7] << 8) | source[6]) / 32768 * 180;
        t = ((source[9]) << 8 | source[8]) / 100;
    }

    magf::magf(std::array<uint8_t, 11> &source) {
        hx = ((source[3] << 8) | source[2]);
        hy = ((source[5] << 8) | source[4]);
        hz = ((source[7] << 8) | source[6]);
        t = ((source[9]) << 8 | source[8]) / 100;
    }

    port::port(std::array<uint8_t, 11> &source) {
        d0 = ((source[3] << 8) | source[2]);
        d1 = ((source[5] << 8) | source[4]);
        d2 = ((source[7] << 8) | source[6]);
        d3 = ((source[9] << 8) | source[8]);
    }

    prehei::prehei(std::array<uint8_t, 11> &source) {
        P = ((source[5] << 24) | (source[4] << 16) | (source[3] << 8) | source[2]);
        H = ((source[9] << 24) | (source[8] << 16) | (source[7] << 8) | source[6]);
    }

    latlon::latlon(std::array<uint8_t, 11> &source) {
        lon = ((source[5] << 24) | (source[4] << 16) | (source[3] << 8) | source[2]);
        lat = ((source[9] << 24) | (source[8] << 16) | (source[7] << 8) | source[6]);
    }

    grsp::grsp(std::array<uint8_t, 11> &source) {
        gpsheight = ((source[3] << 8) | source[2]) / 10;
        gpsyaw = ((source[5] << 8) | source[4]) / 10;
        gpsv = ((source[9] << 24) | (source[8] << 16) | (source[7] << 8) | source[6]);
    }

    foel::foel(std::array<uint8_t, 11> &source) {
        q0 = ((source[3] << 8) | source[2]) / 32768;
        q1 = ((source[5] << 8) | source[4]) / 32768;
        q2 = ((source[7] << 8) | source[6]) / 32768;
        q3 = ((source[7] << 8) | source[6]) / 32768;
    }

    spa::spa(std::array<uint8_t, 11> &source) {
        sn = ((source[3] << 8) | source[2]);
        pdop = ((source[5] << 8) | source[4]) / 32768;
        hdop = ((source[7] << 8) | source[6]) / 32768;
        vdop = ((source[9] << 8) | source[8]) / 32768;
    }
}